package com.p2p.auth.domain.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.p2p.auth.common.enums.ArticleOnTopType;
import com.p2p.auth.common.enums.ArticleStatus;
import com.p2p.auth.common.enums.ArticleType;
import com.p2p.auth.common.enums.Channel;
import lombok.Data;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.*;
import java.util.Date;

/**
 *
 * @author anti
 * @date 2016-11-16
 */
@Entity
@Table(name = "t_article")
@DynamicInsert
@DynamicUpdate
@EntityListeners(AuditingEntityListener.class)
@Data
public class Article extends IdEntity {

    private static final long serialVersionUID = -6657565286531401498L;

    @Column(columnDefinition = "varchar(100) NOT NULL comment '标题'")
    private String title;

    @Column(columnDefinition = "varchar(50) NOT NULL comment '文章类型'")
    @Enumerated(EnumType.STRING)
    private ArticleType type = ArticleType.NONE;

    @Column(columnDefinition = "varchar(50) NOT NULL comment '文章置顶类型'")
    @Enumerated(EnumType.STRING)
    private ArticleOnTopType onTop = ArticleOnTopType.NONE;

    @Column(columnDefinition = "varchar(50) NOT NULL comment '文章状态'")
    @Enumerated(EnumType.STRING)
    private ArticleStatus status = ArticleStatus.DRAFT;

    @Column(columnDefinition = "varchar(50) NOT NULL comment '渠道'")
    @Enumerated(EnumType.STRING)
    private Channel channel = Channel.PC;

    @Column(columnDefinition = "datetime comment '事件时间' ")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date eventDate;

    @Column(columnDefinition = "varchar(255) comment '概要'")
    private String summary;

    @Column(columnDefinition = "text comment '文章详情'")
    private String content;

    @Column(columnDefinition = "varchar(255) comment '视频连接'")
    private String videoUrl;

    @Column(columnDefinition = "varchar(255) comment '图片连接'")
    private String imageUrl;

    @Column(columnDefinition = "varchar(255) comment '外部连接'")
    private String outSideUrl;

    @Column(columnDefinition = "varchar(10) comment '作者'")
    private String author;

    @Column(columnDefinition = "varchar(10) comment '来源'")
    private String source;

    @Column(columnDefinition = "bigint comment '点击次数'")
    private Long clickCounts = 0L;

    @Column(columnDefinition = "varchar(10) default 0 comment '显示顺序' ")
    private String displayOrder;

    @Column(columnDefinition = "varchar(50) NOT NULL comment '唯一识别码'")
    private String uuid;

    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    public Date getEventDate() {
        return eventDate;
    }

    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    public void setEventDate(Date eventDate) {
        this.eventDate = eventDate;
    }


}
